package org.academic.texteditor.helper;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class MessageHelper {

	private static ResourceBundle config = ResourceBundle.getBundle("config");
	
	private static MessageHelper instance;
	private ResourceBundle bundle;

	private MessageHelper() {
		bundle = ResourceBundle.getBundle("application", new Locale(config.getString("language"), config.getString("country")));
	}
	
	public static synchronized MessageHelper getInstance() {
		if (instance == null) {
			instance = new MessageHelper();
		}
		return instance;
	}
	
	public String getMessage(String key) {
		String msg;
		try {
			msg = bundle.getString(key);
		} catch (MissingResourceException e) {
			msg = "?" + key + "?";
		}
		return msg;
	}
	
}
